package pl.edu.pw.perg.compinfodb.entities.attribute;

import pl.edu.pw.perg.compinfodb.entities.IPhysicalElement;
import pl.edu.pw.perg.compinfodb.entities.field.Field;
import pl.edu.pw.perg.compinfodb.entities.field.ListFieldItem;

public class ListAttribute extends Attribute implements IAttribute {

	/**
	 *
	 */
	private static final long serialVersionUID = 8042093723183886434L;

	private ListFieldItem selectedListFieldItem;

	public ListAttribute() {

	}

	public ListAttribute(ListFieldItem lfi, Field field, IPhysicalElement e) {
		super(field, e);
		selectedListFieldItem = lfi;
	}

	public ListAttribute(Field field, IPhysicalElement e) {
		super(field, e);
	}

	public ListFieldItem getSelectedListFieldItem() {
		return selectedListFieldItem;
	}

	public void setSelectedListFieldItem(ListFieldItem selectedListFieldItem) {
		this.selectedListFieldItem = selectedListFieldItem;
	}

	@Override
	public String toString() {
		return selectedListFieldItem.toString();
	}

	public boolean matchesFilter(IAttribute a) {
		if(a == null)
			return true;
		String filter = a.getTextValue();
		if(selectedListFieldItem.toString().contains(filter))
			return true;
		return false;
	}

}
